package com.yxj02;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

public class ListIteratorDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("hello");
        list.add("world");
        list.add("java");
        //通过List集合的listIterator()方法得到
/*        ListIterator lit = list.listIterator();
        while(lit.hasNext()) {
            String s = (String) lit.next();
            System.out.println(s);
        }
        System.out.println("---------");
        while(lit.hasPrevious()) {
            String s = (String) lit.previous();
            System.out.println(s);
        }*/
        //获取列表迭代器
        ListIterator<String> lit = list.listIterator();
        while(lit.hasNext()) {
            String s = lit.next();
            if(s.equals("world")) {
                lit.add("javaee");
            }
        }
        System.out.println(list);
    }
}
